<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Slider</title>
		<style>
		.imgbtn
		{
			margin-left:3px;
			margin-right:3px;
			cursor:hand;
			padding:5px;
		}
		.imgbtn:hover
		{
			background-color:gold;
		}
		</style>
		<script type='text/javascript' src='../../Core/GalleryLibrary.js'></script>
		<script type='text/javascript' src='../../Core/GalleryMenu.js'></script>
		<script type='text/javascript'>
		window.onerror=function(a,b,c)
		{
			alert(a,b,c);
		}
		var gallerybrowser=opener._galleryslider.Browser;
		var optionalCategory=opener._galleryslider.optionalCategory;
		var theme=gallerybrowser.Param.Theme;
		document.write("<link rel='stylesheet' href='../../Theme/"+theme+"/Style.css' />");
		</script>
	</head>
	<body class="Slider">
		<div id='photocontainer1' style='position:absolute;left:0px;top:0px;text-align:center;display:none'></div>
		<div id='photocontainer2' style='position:absolute;left:0px;top:0px;text-align:center;display:none'></div>
		<div id='toolbar' style='position:absolute;bottom:12px;width:100%;z-index:55555;text-align:center'>
			<div id='photoname'>
			</div>
			<div style='margin-top:5px;text-align:center'>
				<img class='imgbtn' align=absmiddle id="btnSpeed" onclick='ShowSpeedMenu(this)' />
				<img class='imgbtn' align=absmiddle id='btnPrev' onclick='MovePrev()' />
				<img class='imgbtn' align=absmiddle id='btnPausePlay' onclick="TogglePause()" />
				<img class='imgbtn' align=absmiddle id='btnNext' onclick='MoveNext()' />
				<img class='imgbtn' align=absmiddle id="btnExit" onclick='window.close()' />
			</div>
		</div>
	</body>
	<script type='text/javascript'>
	
	function SetImgSrc(id,file)
	{
		document.getElementById(id).src="../../Theme/"+theme+"/Images/"+file+".png";
	}
	SetImgSrc("btnSpeed","standard-config");
	SetImgSrc("btnPrev","standard-slider-prev");
	SetImgSrc("btnPausePlay","standard-slider-pause");
	SetImgSrc("btnNext","standard-slider-next");
	SetImgSrc("btnExit","standard-exit");
	
	var categories=[];
	var photos=[];
	

	function ShowSilider()
	{
		photos=[];
		for(var i=0;i<categories.length;i++)
		{
			var cate=categories[i];
			for(var k=0;k<cate.Photos.length;k++)
			{
				photos.push(cate.Photos[k]);
			}
		}
		if(photos.length==0)
		{
			alert("NoPhoto!");
			window.close();
			return;
		}
		for(var i=0;i<photos.length;i++)
		{
			photos[i].slidercacheimage=null;
		}
		ContinuePlay();
	}
	
	var times=0;
	var index=-1;
	var nextimage=null;
	var photomap=[];
	var timerid;
	var cshow,chide;
	var alpha=0;
	var timermode="ContinuePlay";
	var paused=false;

	var _speed=3.0;
	
	function ShowSpeedMenu(img)
	{
		var imgbase="../../Theme/"+theme+"/";
		var selimg=imgbase+"Images/standard-selected.png";
		var menu=CreateGalleryMenu(imgbase);
		menu.Add(1,"Faster",_speed==1.5?selimg:null,function(){
			SetSpeed(1.5);
		});
		menu.Add(1,"Medium",_speed==3.0?selimg:null,function(){
			SetSpeed(3.0);
		});
		menu.Add(1,"Slower",_speed==6.0?selimg:null,function(){
			SetSpeed(6.0);
		});
		menu.Show(img,0,img.offsetHeight);
	}
		
	function GetSpeed()
	{
		return _speed*1000;
	}
	function SetSpeed(spd)
	{
		_speed=spd;
		if(timermode=="ContinuePlay")
		{
			clearTimeout(timerid);
			timerid=setTimeout(ContinuePlay,GetSpeed());
		}
	}
	
	function TogglePause()
	{
		if(paused)
		{
			paused=false;
			ContinuePlay()
		}
		else
		{
			paused=true;
			if(timermode=="ContinuePlay")
				clearTimeout(timerid);
		}
		SetImgSrc("btnPausePlay",paused?"standard-slider-play":"standard-slider-pause");
		return paused;
	}
	
		
	function ContinuePlay()
	{
		if(paused)return;
		
		if(GalleryHasFloatObject())
			return timerid=setTimeout(ContinuePlay,GetSpeed());
		
		times++;
		index++;
		if(index>=photos.length)index=0;
		
		ShowPhotoImpl()
	}
	
		
	function MovePrev()
	{
		clearTimeout(timerid);
		if(cshow)
		{
			alpha=95;
			PlayAlpha();
			clearTimeout(timerid);
		}
		
		times++;
		index--;
		if(index<0)index=photos.length-1;

		ShowPhotoImpl()
	}
	function MoveNext()
	{
		clearTimeout(timerid);
		if(cshow)
		{
			alpha=95;
			PlayAlpha();
			clearTimeout(timerid);
		}

		times++;
		index++;
		if(index>=photos.length)index=0;
		
		ShowPhotoImpl()
	}

	
	function ShowPhotoImpl()
	{
		var photo=photos[index];
		if(!photo.slidercacheimage)
		{
			photo.slidercacheimage=document.createElement("IMG");
			photo.slidercacheimage.border=0;
			photo.slidercacheimage.src=photo.Url;
		}
		
		var np=photos[index+1];
		if(np && !np.slidercacheimage)
		{
			np.slidercacheimage=document.createElement("IMG");
			np.slidercacheimage.border=0;
			np.slidercacheimage.src=np.Url;
		}

		
		var container1=document.getElementById('photocontainer1');
		var container2=document.getElementById('photocontainer2');
		
		
		if(times%2==0)
		{
			cshow=container1;
			chide=container2;
		}
		else
		{
			cshow=container2;
			chide=container1;
		}
		
		var bodywidth=Math.max(document.body.clientWidth,document.documentElement.clientWidth);
		var bodyheight=Math.max(document.body.clientHeight,document.documentElement.clientHeight);
		
		document.getElementById('toolbar').style.width=bodywidth+"px";
		
		chide.style.width=cshow.style.width=bodywidth+"px";

		var scale = Math.min( (bodywidth-48)/photo.Width , (bodyheight-96)/photo.Height );
		if(scale>1)scale=1;
		var photoheight=Math.floor(photo.Height*scale);
		photo.slidercacheimage.style.width=Math.floor(photo.Width*scale)+"px";
		photo.slidercacheimage.style.height=photoheight+"px";
		
		cshow.style.paddingTop=Math.floor((bodyheight-48-photoheight)/2)+"px";
		
		document.getElementById('photoname').innerHTML=""
		document.getElementById('photoname').appendChild(document.createTextNode(photo.Title));
		
		cshow.style.display="";
		
		cshow.innerHTML="";
		//cshow.appendChild(photo.slidercacheimage);
		cshow.appendChild(GalleryCreateImage(photo.slidercacheimage.src,Math.floor(photo.Width*scale),photoheight));
		
		cshow.style.zIndex=8;
		chide.style.zIndex=5;
		
		cshow.onclick=MoveNext;
		
		
		alpha=0;
		
		PlayAlpha();
	}
	

	function PlayAlpha()
	{
		alpha+=10;
		
		GallerySetOpacity(cshow,alpha);
		
		//chide.style.filter="alpha(opacity="+(100-alpha)+")";
		//chide.style.mozOpacity=String(1-alpha/100);
		//chide.style.opacity=String(1-alpha/100);

		if(alpha<100)
		{
			timermode="PlayAlpha"
			timerid=setTimeout(PlayAlpha,GetSpeed()/40);
		}
		else
		{
			chide.style.display="none";
			
			timermode="ContinuePlay"
			timerid=setTimeout(ContinuePlay,GetSpeed());
		}
	}

	
	document.onkeydown=function(event)
	{
		event=event||window.event;
		if(event.keyCode==27)
		{
			window.close();
		}
	}
	window.onload=function()
	{
		if(optionalCategory)
		{
			categories=[optionalCategory];
			ShowSilider();
		}
		else
		{
			categories=gallerybrowser.GetCategories();
			ShowSilider();
		}
	}
	
	
	</script>
</html>
